package cn.stylefeng.guns.modular.business.service.impl;

import cn.stylefeng.guns.modular.business.dto.ProjectQuery;
import cn.stylefeng.guns.modular.business.entity.Device;
import cn.stylefeng.guns.modular.business.entity.Project;
import cn.stylefeng.guns.modular.business.mapper.ProjectMapper;
import cn.stylefeng.guns.modular.business.service.ProjectService;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.dsctn.api.annotation.DataSource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;


    @Override
    @DataSource(name = "business")
    public PageResult<Project> findPage(ProjectQuery projectQuery) {

        Page<Project> page = new Page<>(projectQuery.getPageNo(),projectQuery.getPageSize());
        QueryWrapper<Project> qw = new QueryWrapper<>();
        qw.select("id","project_name","project_id");
        qw.like(StringUtils.isNotBlank(projectQuery.getProjectName()), Project.COL_PROJECT_NAME,projectQuery.getProjectName());
        qw.orderByDesc(Device.COL_ID);
        this.projectMapper.selectPage(page,qw);
        PageResultFactory.createPageResult(page);
        return PageResultFactory.createPageResult(page);
    }
}
